<?php
/*
 * Author:      jack@yeahcpa.com
 * Date:        2011-10-09
 * Intro:       守护进程，用于定时启动清理模块
 */

include('path.inc.php');

include(PATH . 'includes/class/check.class.php');

define('MAX_THREAD', 1);        //清理线程最大数量
define('IDLE_TIME', 1 * 60); //清理线程启动间隔(秒)

session_id("YEAHTRACE_DEAMON.PHP");
session_start();
//检查是否已有deamon运行中,有则退出脚本
if(!isset($_SESSION['RUN'])){
    $_SESSION['RUN'] = true;
}
elseif(true == $_SESSION['RUN']){
    die('running');
}
//启动deamon进程，设置脚本运行时限为无限
set_time_limit(0);
$last_start_time = time();

$check = new YeahTraceCheck();

while(true)
{
    sleep(1);

    if(IDLE_TIME >= (time() - $last_start_time)){
        continue;
    }

    $check->Run();
}

?>
